package com.gadgets;

import com.gadgets.cm01.auth.advisor.impl.RoleAuthCheckInterceptor;
import com.gadgets.framework.common.util.CacheUtils;
import com.gadgets.framework.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.MappedInterceptor;

/**
 * 功能说明：
 *
 * @author Unclexiu
 * @version V202101.00.000
 * @data 2022-09-08
 * 修改记录：  修改日期          修改人员    修改说明
 * 2022-09-08  xiujunqing   创建文件
 */
@Configuration
public class GadgetsCm01CheckStart implements WebMvcConfigurer {

	@Autowired
	private CacheUtils cacheUtils;
	@Autowired
	private RedisUtil redisUtil;

	/**
	 * Add Spring MVC lifecycle interceptors for pre- and post-processing of
	 * controller method invocations. Interceptors can be registered to apply
	 * to all requests or be limited to a subset of URL patterns.
	 * <p><strong>Note</strong> that interceptors registered here only apply to
	 * controllers and not to resource handler requests. To intercept requests for
	 * static resources either declare a
	 * {@link MappedInterceptor MappedInterceptor}
	 * bean or switch to advanced configuration mode by extending
	 * {@link WebMvcConfigurationSupport
	 * WebMvcConfigurationSupport} and then override {@code resourceHandlerMapping}.
	 *
	 * @param registry  拦截器注册器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new RoleAuthCheckInterceptor(cacheUtils, redisUtil));
	}

	public static void main(String[] args) {
		SpringApplication.run(new Class[]{
				GadgetsCm01Start.class,
				GadgetsCm01CheckStart.class
		}, args);
	}

}
